package org.csu.webjpetstoreback.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Builder
@NoArgsConstructor
@Getter
@Data
@Repository
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class CommonResponse<T> {
    private int status;
    private String message;
    private T data;


    //不同的构造方法
    private CommonResponse(int status, String message){
        this.status = status;
        this.message = message;
    }
    private CommonResponse(int status, String message, T data){
        this.status = status;
        this.message = message;
        this.data = data;
    }
    

    public static  <T>CommonResponse<T> BackForSuccess(){
        return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc());
    }

    public static  <T>CommonResponse<T> BackForSuccess(String message){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message);
    }

    public static  <T>CommonResponse<T> BackForSuccess(T data){
        System.out.println(data);
        return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc(),data);
    }




    public static  <T>CommonResponse<T> BackForError(){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDesc());
    }

    public static  <T>CommonResponse<T> BackForError(String message){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(), message);
    }

    public static  <T>CommonResponse<T> BackForError(int code,String message){
        return new CommonResponse<>(code,message);
    }




}
